<#ftl output_format="HTML" auto_esc=true> 
<@h.commonHead title="后台管理系统" keywords="开源,永久免费" description="springrain开源系统管理后台"/>

<script type="text/javascript" src="${ctx}/js/ztree/js/jquery.ztree.all-3.5.js"></script>
<script type="text/javascript" src="${ctx}/js/ztree/js/ztreeUtils.js"></script>
<script type="text/javascript" src="${ctx}/js/artTemplate/artTemplate.js"></script>
<link rel="stylesheet" href="${ctx}/js/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<link rel="stylesheet" href="${ctx}/css/custom/common/myztree.css" type="text/css">


<script>
    jQuery(function(){ 
        /*
        全选、反选
        */
        jQuery("#checkAll").bind('click',function(){
            var _is_check=jQuery(this).get(0).checked;
            jQuery("input[name='check_li']").each(function(_i,_o){
                jQuery(_o).get(0).checked=_is_check;
            });
        });
        
        //加载栏目列表
        loadChannelList();
    });
    function del(_id){
        delWrap(_id,"${ctx}/system/cms/channel/delete");
    }
    
    function loadChannelList(){
        jQuery.post("${ctx}/system/cms/channel/list/json",function(_json) {
            if (_json.status == "success") {
                //树节点点击事件
                var treeNodeClickFunc = function(event, treeId, treeNode){
                    if(jQuery(event.target).hasClass("myctr")){
                        //阻止事件冒泡
                        return;
                    } 
                    saveType=1;
                    jQuery(".add_div a").attr('tid',treeNode.tId);
                    if (treeNode.pid!='null'){
                    	showdata(treeNode);
                    }
                };
                //添加子栏目方法回调
                var addSubChannelFunc = function(tree,id,e){
                    jQuery("#"+id+"_a").addClass("curSelectedNode");
                    saveType=0;
                    var node = tree.getNodeByTId(id);
                    jQuery("#updateForm")[0].reset();
                    jQuery("#pname").val(node.name);
                    jQuery("#pid").val(node.id);
                    jQuery("#imgIcon").html('');
                    jQuery("#menuIcon").val('');
                    jQuery(".add_div").css('display','none');
                    springrain.stopBubble(e);
                };
                //删除方法回调
                var delChannelFunc = function(treeSetting,treeObj){
                	var id = treeObj.id;
                    jQuery("#"+id+"_a").addClass("curSelectedNode");
                    console.log(id);
                    console.log(treeSetting);
                    var node = treeSetting.getNodeByTId(id);
                    console.log(node);
                    /* springrain.confirm('删除这个菜单，是否继续?', function(index) {
                        var id = node.id;
                        if (!id || id == "") {
                            springrain.alert('请选择你要删除的记录!');
                            return false;
                        } else {
                            var _url = "${ctx}/system/menu/delete";
                            var listurl = "${ctx}/system/menu/list";
                            var data = {
                                "id" : id
                            };
                            springrain.ajaxpostonlayer(_url, listurl, data, '删除菜单成功！');
                        }
                        layer.close(index);
                    }); */
                };
                var opt = {
                    'hasMenu':true,
                    'id':'channelListTree',
                    'data':_json.data,
                    'treeNodeClick':treeNodeClickFunc,
                    'btns':[
                        {'text':'添加子栏目','callback':addSubChannelFunc},
                        {'text':'删除','callback':delChannelFunc}
                    ]
                };
                springrain.tree(opt);
            }else{
                myalert(_json.message);
            }
        });
    }
    
    //树节点点击方法
    function showData(treeNode){
    	$("#updateForm select ").each(function() {
			$(this).find('option:first').attr('selected','selected');
		});
		//console.log(result);
		for ( var s in result) {
			set_val(s, result[s]);
		}				
		var _pid = result["pid"];
		if ((!_pid) || _pid == null || _pid == "null" || _pid == "") {
			jQuery("#pid").val("");
		} else {
			jQuery("#pid").val(_pid);
		}
		var _imgIcon=result["menuIcon"];
		if ((!_imgIcon) || _imgIcon == null || _imgIcon == "null" || _imgIcon == "") {
		}else{
			jQuery("#imgIcon").html(_imgIcon);
		}
		var _pNode = result.getParentNode();
		if (_pNode) {
			jQuery("#pname").val(_pNode["name"]);
		} else {
			jQuery("#pname").val("");
		}
    }
</script>

</head>
<body>
    <div class="layui-layout layui-layout-admin">
        <@h.naviHeader /><@h.leftMenu />
        <!-- 主体内容开始 -->
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title site-demo-title">
                <li style="float: right;">
                    <@shiro.hasPermission name="/system/cms/channel/update" >
                    <button type="button" class="layui-btn layui-btn-small"
                        data-action="${ctx}/system/cms/channel/update/pre">
                        <i class="layui-icon layui-icon-specil">&#xe61f;</i>新增
                    </button>
                    </@shiro.hasPermission>
                    <@shiro.hasPermission name="/system/cms/channel/export" >
                    <button type="button" class="layui-btn layui-btn-small">
                        <i class="layui-icon layui-icon-specil">&#xe609;</i>导出
                    </button>
                    </@shiro.hasPermission>
                    <@shiro.hasPermission name="/system/cms/channel/import" >
                    <button type="button"
                        class="layui-btn layui-btn-warm layui-btn-small">
                        <i class="layui-icon layui-icon-specil">&#xe601;</i>导入
                    </button>
                    </@shiro.hasPermission>
                    <@shiro.hasPermission name="/system/cms/channel/delete" >
                    <button type="button"
                        class="layui-btn layui-btn-danger layui-btn-small">
                        <i class="layui-icon">&#xe640;</i>批量删除
                    </button>
                    </@shiro.hasPermission>
                </li>
            </ul>

            <div class="layui-body layui-tab-content site-demo-body">
                <div class="layui-tab-item layui-show">
                    <div class="layui-main">
                        <div class="container-fluid" style="overflow:hidden;">
                            <div class="row">
                                <div class="fl per20" style="min-width:360px">
                                    <ul id="channelListTree" class="ztree"></ul>
                                </div>
                                <div class="fl per75 rlt">
                               		<form id="updateForm" name="updateForm" action="${ctx}/system/cms/channel/update" method="post" class="layui-form">
                               			<input type="hidden" id="id" name="id"
										value="" />
										<input type="hidden" id="siteId" name="siteId" value=""/>
										<div class="layui-form-item col-lg-6">
											<label class="layui-form-label">栏目名称*</label>
											<div class="layui-inline col-lg-5">
												<input type="text" name="name" id="name" datatype="*"
													nullmsg="不能为空" errormsg="不能为空！" autocomplete="off"
													class="layui-input" value="">
											</div>
											<div class="layui-inline valid-info"></div>
										</div>
										<div class="layui-form-item col-lg-6">
											<label class="layui-form-label">父级栏目*</label>
											<div class="layui-inline col-lg-5">
												<input type="text" name="pid" id="pid"  class="layui-input" value="">
											</div>
											<div class="layui-inline valid-info"></div>
										</div>
										<div class="layui-form-item col-lg-6">
											<label class="layui-form-label">编号</label>
											<div class="layui-inline col-lg-5">
												<input type="text" name="comcode" id="comcode" datatype="*"
													nullmsg="不能为空" errormsg="不能为空！" autocomplete="off"
													class="layui-input" value="">
											</div>
											<div class="layui-inline valid-info"></div>
										</div>
										
										<div class="layui-form-item col-lg-6">
											<label class="layui-form-label">级别</label>
											<div class="layui-inline col-lg-5">
												<input type="text" name="positionLevel" id="positionLevel"
													datatype="*" nullmsg="不能为空" errormsg="不能为空！"
													autocomplete="off" class="layui-input"
													value="">
											</div>
											<div class="layui-inline valid-info"></div>
										</div>
										<div class="layui-form-item col-lg-6">
											<label class="layui-form-label">关键字*</label>
											<div class="layui-inline col-lg-5">
												<input type="text" name="keywords" id="keywords" datatype="*"
													nullmsg="不能为空" errormsg="不能为空！" autocomplete="off"
													class="layui-input"
													value="">
											</div>
											<div class="layui-inline valid-info"></div>
										</div>
										<div class="layui-form-item col-lg-6">
											<label class="layui-form-label">描述*</label>
											<div class="layui-inline col-lg-5">
												<input type="text" name="description" id="description"
													datatype="*" nullmsg="不能为空" errormsg="不能为空！"
													autocomplete="off" class="layui-input"
													value="">
											</div>
											<div class="layui-inline valid-info"></div>
										</div>
										<div class="layui-form-item col-lg-6">
											<label class="layui-form-label">排序*</label>
											<div class="layui-inline col-lg-5">
												<input type="text" name="sortno" id="sortno" datatype="*"
													nullmsg="不能为空" errormsg="不能为空！" autocomplete="off"
													class="layui-input" value="">
											</div>
											<div class="layui-inline valid-info"></div>
										</div>
										<div class="layui-form-item col-lg-6">
											<label class="layui-form-label">状态 *</label>
											<div class="layui-inline col-lg-5">
												<select name="active" id="active" lay-verify="required">
													<option value="1">是</option>
													<option value="0">否</option>
												</select>
											</div>
											<div class="layui-inline valid-info"></div>
										</div>
										<div class="layui-form-item change-submit col-lg-5 tc">
											<div class="layui-inline">
												<button type="button" class="layui-btn" id="smtbtn">立即提交</button>
												<button type="button" class="layui-btn layui-btn-primary"
													id="rstbtn">重置</button>
											</div>
										</div>
                               		</form>     
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 主体内容结束 -->
        <@h.footer />
    </div>
    
    <div id="div_channelZtree" style='display:none;'>
        <ul id="channelZtree" class="ztree"></ul>
    </div>

</body>
</html>

